package com.common.utils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 读取redis配置文件
 */
public class RedisPropertiesUtils {
    //是否使用redis
    public static String useRedis="false";
    //验证码过期时间
    public static Integer codeExpire=1800;


    static {
        InputStream in=null;
        try {
            //加载redis配置
            in =  RedisPropertiesUtils.class.getClassLoader().getResourceAsStream("config"+ File.separator+"env"+File.separator+"redis.properties");
            Properties props = new Properties();
            props.load(in);
            useRedis=props.getProperty("redis.useRedis");
            if("true".equals(useRedis)){
                codeExpire=Integer.parseInt(props.getProperty("redis.code.expire"));
            }

        }catch (IOException ie){
            throw new IllegalArgumentException("加载配置文件失败！", ie);
        }finally {
            try {
                if(null!=in){
                    in.close();
                }
            }catch (IOException  io){
                io.printStackTrace();
            }finally {
                try {
                    if(null!=in){
                        in.close();
                    }
                }catch (IOException ie){
                    ie.printStackTrace();
                }
            }


        }
    }
}
